﻿using AutoMapper;
using YDT_UserService.Applictions.DTOs;
using YDT_UserService.Domain.Entities;

namespace YDT_UserService.Applictions.Mappings
{
    public class MappingProfile : Profile
    {
        public MappingProfile()
        {
            // 用户映射配置
            CreateMap<User, UserDto>()
                .ForMember(dest => dest.Status,
                           opt => opt.MapFrom(src => src.Status.ToString()));

            // 创建用户映射配置
            CreateMap<CreateUserDto, User>()
                .ForMember(dest => dest.PasswordHash, opt => opt.Ignore()); // 密码需要单独处理

            // 更新用户映射配置
            CreateMap<UpdateUserDto, User>()
                .ForAllMembers(opts => opts.Condition((src, dest, srcMember) => srcMember != null));
        }
    }
}
